<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <!-- <link rel="stylesheet" href="../css/select2.min.css">
    <link rel="stylesheet" href="../css/select2-bootstrap4.min.css"> -->
    <link rel="stylesheet" href="../css/style.css">
 
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }
        .form-control-theme {
            border: 2px solid #F2F2F2 !important;
            border-radius: 0;
        }
        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }
        @media (min-width: 375px) {
            .filedlabel {
                width: 100%;
                max-width: 9.6rem;
                font-size: 1rem;
            }
        }
        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 240px;
            margin: 0 auto;
            display: block;
        }
        .nav-tabs {
            position: sticky;
            top: 0;
            padding-top: 10px;
            z-index: 999;
            background-color: #fff;
        }
        
        .tab-content {
            padding: 0 10px;
            overflow-x: hidden;
            overflow-y: scroll;

        }
        /* .scrollable-scrollbar {
            position: absolute;
            top: 0;
            right: 0;
            width: 10px;
            height: 100%;
            background-color: #f5f5f5;
        }

        .scrollable-track {
            position: relative;
            width: 100%;
            height: 100%;
        }

        .scrollable-thumb {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 50px;
            background-color: #888;
            cursor: pointer;
        } */
        /* 自定义滚动条样式 */
        /* .tab-content::-webkit-scrollbar {
            width: 10px;
            background-color: #f5f5f5;
        }

        .tab-content::-webkit-scrollbar-thumb {
            background-color: #888;
            height: 30px;
        }

        .tab-content::-webkit-scrollbar-thumb:hover {
            background-color: #555;
        }
         */

        .logodiv {
            text-align: center;
        }

        .logodiv h1 {
            font-size: 1.4rem;
            color: #03357a;
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .logodiv h2 {
            font-size: 1.5rem;
            margin-bottom: 80px;
        }

        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }
        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }

        .bootstrap-select {
            width: calc(100% - 0px) !important;
            position: relative;
        }
        .bootstrap-select option{
            position: absolute;
            top: 100%;
            left: 0;
        }
        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }

        .myselect {
            width: calc(100% - 0px);
        }
        .btn-action:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="container2">
            <!-- 建立收货弹出框 -->
            <div class="modal fade"  id="exampleModal" tabindex="-1"
                aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">{{lan['New_Receipt']}} </h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="row  align-items-center">
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['PO_No']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" @blur="poNumChange" v-model="searchdata.PONum"
                                                :placeholder="lan['PO_NO_placeholder']"
                                                class="form-control form-control-theme">
                                            <!-- <select  v-if="select_btn == true"   v-model="searchdata.PONum" id="vendorselect2"
                                                @change="updateSearch" class="form-select myselect myselect2 form-control-theme"
                                                data-live-search="true" data-select-all-text = "false">
                                                <option v-for="(item,index) in polist" :key="index"
                                                    :data-num="item.VendorNum" :value="item.PONum"
                                                    :data-name="item.PONum" :data-tokens="item.PONum">
                                                    {{item.PONum}}</option>
                                            </select> -->
                                        </div>
                                       
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['DN_No']}}</div>
                                        <div id="inputflied" class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.PackSlip"
                                                :placeholder="lan['DN_No_placeholder']"
                                                class="form-control form-control-theme" value="ABC-0001">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Supplier_ID']}}
                                        </div>
                                        <div  class="p-2 flex-grow-1 bd-highlight">

                                            <input type="text" v-model="searchdata.VendorID"
                                            :placeholder="lan['Supplier_ID_placeholder']"
                                            class="form-control form-control-theme" value="">
                                            <!-- <select onchange="getvendorName(this)"
                                                :title="lan['Supplier_ID_placeholder']" v-model="searchdata.VendorID"
                                                id="vendorselect"
                                                class="form-select myselect myselect1 form-control-theme"
                                                data-live-search="true" :placeholder="lan['Supplier_ID_placeholder']"
                                                :aria-label="lan['Supplier_ID_placeholder']">
                                                <option v-for="(item,index) in vendors" :key="index"
                                                    :data-num="item.VendorNum" :value="item.VendorID"
                                                    :data-name="item.Name" :data-tokens="item.VendorID">
                                                    {{item.VendorID}}</option>
                                            </select> -->
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Supplier_Name']}}
                                        </div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.VendorName"
                                                :placeholder="lan['Supplier_Name_placeholder']" disabled
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>

                               
    
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Delivery_Date']}}
                                        </div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="date" v-model="searchdata.ArrivedDate"
                                                :placeholder="lan['Delivery_Date_placeholder']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>
                                   <!-- 进口编号 -->
                                   <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Import_Number']}}</div>
                                        <div id="inputflied" class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.ImportNum"
                                                class="form-control form-control-theme">
                                        </div>
                                    </div>
                                </div>


                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['User']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.name" disabled
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>


                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh filedlabel"></div>
                                        <div  class="p-2 flex-grow-1 bd-highlight" style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
                                            <input type="checkbox" style="margin-right: 5px;" v-model="IncludingClosed"   name="IncludingClosed" id="IncludingClosed">
                                            <!-- 包括已结按钮 -->
                                            <button  :disabled="!IncludingClosed" tapmode="" class="btn btn-primary btn-action btn-close">{{lan['Including_Closed']}}</button>
                                        </div>
                                    </div>
                                </div>
                             

                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" onclick="loadData(0)"
                                class="btn btn-primary btn-tiqu btn-lg mt-2 mt-md-0">{{lan['Get_PO']}}</button>
                        </div>
                    </div>
                </div>
            </div>
            <ul class="nav nav-tabs" id="myTab" role="tablist">
                <li class="nav-item" role="presentation">
                    <a class="nav-link active " id="home-tab" data-toggle="tab" href="#home" role="tab"
                        aria-controls="home" aria-selected="true">{{lan['Open_PO']}}</a>
                </li>
                <li class="nav-item" role="presentation">
                    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab"
                        aria-controls="profile" aria-selected="false">{{lan['Part_Receipt']}}</a>
                </li>

            </ul>
            <div class="tab-content" id="myTabContent">
                <div class="tab-pane  show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                    <h2 class="buytitle"><span>({{lan['Pls_select']}})</span></h2>

                    <div v-if="checkShow" class="row align-items-center">
                        <div v-for="(item,index) in list" :key="'shou'+index" v-if="item.shoucai == 1" id="shouitem"
                            class="col-12 col-sm-6 col-md-4">
                            <div class="d-flex bd-highlight align-items-start">
                                <div class="pt-2 bd-highligh">
                                    <div class="custom-control custom-switch">
                                        <!-- 请选择 -->
                                        <input :disabled="Lot_btn" type="checkbox" v-model='item.itemChecked' @change="toshou(index,item)" class="custom-control-input"
                                            :id="'Switch'+item.PORel_PONum+'-'+item.PORel_POLine+'-'+item.PORel_PORelNum">
                                        <label class="custom-control-label"
                                            :for="'Switch'+item.PORel_PONum+'-'+item.PORel_POLine+'-'+item.PORel_PORelNum"></label>
                                    </div>
                                </div>
                                <div class="pt-2 flex-grow-1 bd-highlight">
                                    <table class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td style="min-width: 80px;" class="ttl">{{lan['No']}} </td>
                                            <td class="ttl">{{lan['Line']}}</td>
                                            <td class="ttl">{{lan['RelNum']}}</td>
                                            <td  v-if="item.RcvInspectionReq !=null  && item.RequiredFAI_c ==false" class="ttl" style="width: 35px;text-align: center;">{{lan['Inspection']}}</td>
                                            <td  v-if="item.RequiredFAI_c !=false" class="ttl" style="width: 35px;text-align: center;">FAI</td>
                                        </tr>
                                        <tr>
                                            <td style="min-width: 80px;">{{item.PORel_PONum}}</td>
                                            <td>{{item.PORel_POLine}}</td>
                                            <td>{{item.PORel_PORelNum}}</td>
                                            <td  v-if="item.RcvInspectionReq !=null  && item.RequiredFAI_c ==false" style="width: 35px;text-align: center;"> <input type="checkbox"  v-model="item.RcvInspectionReq"  disabled  /></td>
                                            <td  v-if="item.RequiredFAI_c !=false" style="width: 35px;text-align: center;"> <input type="checkbox" v-model="item.RequiredFAI_c"    disabled  /></td>
                                        </tr>
                                        <tr>
                                            <td colspan="4"  class="ttl">{{lan['Part']}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="4">{{item.PODetail_PartNum}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="4"  class="ttl">{{lan['Desc']}} </td>
                                            
                                        </tr>
                                        <tr>
                                            <td colspan="4">{{item.PODetail_LineDesc}}</td>
                                        </tr>
                                        <tr>
                                            <td style="min-width: 80px;" class="ttl">{{lan['XRelQty']}}</td>
                                            <td class="ttl">{{lan['Received']}}</td>
                                            <td class="ttl">{{lan['Due']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{processNumber(item.PORel_XRelQty,item.UOM_NumOfDec)}}<span>{{item.UOM_UOMCode}}</span></td>
                                            <td>{{processNumber(item.PORel_ReceivedQty,item.UOM_NumOfDec)}}<span>{{item.UOM_UOMCode}}</span></td>
                                            <td>{{formatDate(item.PORel_DueDate)}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl">{{lan['Job_No']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.PORel_JobNum}}</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="tab-pane " id="profile" role="tabpanel" aria-labelledby="profile-tab">
                    <h2 class="buytitle"><span>({{lan['Cancel']}})</span></h2>



                    <div v-if="checkShow"   class="row   align-items-center">
                        <div v-for="(item,k) in list" :key="'cai'+k" v-if="item.shoucai == 2" id="caiitem"
                            class="col-12 col-sm-6 col-md-4">
                            <div class="d-flex bd-highlight align-items-start">
                                <div class="pt-2 bd-highligh">
                                    <div class="custom-control custom-switch">
                                        <!-- 请选择 -->
                                        <input :disabled="Lot_btn" type="checkbox" @change="toshou(k,item)" class="custom-control-input"
                                            :id="'Switch'+item.PORel_PONum+'-'+item.PORel_POLine+'-'+item.PORel_PORelNum">
                                        <label class="custom-control-label"
                                            :for="'Switch'+item.PORel_PONum+'-'+item.PORel_POLine+'-'+item.PORel_PORelNum"></label>
                                    </div>
                                </div>
                                <div class="pt-2 flex-grow-1 bd-highlight">
                                    <table class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td style="min-width: 80px;" class="ttl">{{lan['No']}}</td>
                                            <td class="ttl">{{lan['Line']}}</td>
                                            <td class="ttl">{{lan['RelNum']}}</td>
                                            <td class="ttl"  v-if="item.RcvInspectionReq !=null  && item.RequiredFAI_c == false" style="width: 35px;text-align: center;">{{lan['Inspection']}}</td>
                                            <td class="ttl" v-if="item.RequiredFAI_c !=false" style="width: 35px;text-align: center;">FAI</td>
                                        </tr>
                                        <tr>
                                            <td style="min-width: 80px;">{{item.PORel_PONum}}</td>
                                            <td>{{item.PORel_POLine}}</td>
                                            <td>{{item.PORel_PORelNum}}</td>
                                            <td  v-if="item.RcvInspectionReq !=null  && item.RequiredFAI_c ==false" style="width: 35px;text-align: center;"> <input type="checkbox" v-model="item.RcvInspectionReq"  disabled /></td>
                                            <td  v-if="item.RequiredFAI_c != false" style="width: 35px;text-align: center;"> <input type="checkbox" v-model="item.RequiredFAI_c"   disabled /></td>
                                        </tr>
                                        <tr>
                                            <td colspan="4"  class="ttl">{{lan['Part']}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="4">{{item.PODetail_PartNum}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="4"  class="ttl">{{lan['Desc']}} </td>
                                            
                                        </tr>
                                        <tr>
                                            <td colspan="4">{{item.PODetail_LineDesc}}</td>
                                        </tr>
                                        <tr>
                                            <td style="min-width: 80px;" class="ttl">{{lan['XRelQty']}}</td>
                                            <td class="ttl">{{lan['Received']}}</td>
                                            <td class="ttl">{{lan['Due']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{processNumber(item.PORel_XRelQty,item.UOM_NumOfDec)}}<span>{{item.UOM_UOMCode}}</span></td>
                                            <td>{{processNumber(item.PORel_ReceivedQty,item.UOM_NumOfDec)}}<span>{{item.UOM_UOMCode}}</span></td>
                                            <td>{{formatDate(item.PORel_DueDate)}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" class="ttl">{{lan['Job_No']}}</td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">{{item.PORel_JobNum}}</td>
                                            <td  style="display: flex;align-items: center;">
                                                <input type="checkbox" style="margin-right: 5px;" v-model="list[k].Received"   name="Received" id="Received">
                                                <span>Received</span>
                                            </td>
                                        </tr>
                                      
                                    </table>
                                    <table class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td class="ttl">{{lan['Delivery_QTY']}}</td>
                                            <td class="ttl">{{lan['WareHouseCode']}}</td>
                                            <td class="ttl">{{lan['BinNum']}}</td>
                                            <!-- <td class="ttl">{{lan['Total_Carton_QTY']}}</td> -->

                                        </tr>
                                        <tr class="allinput">
                                            <td>
                                                <!-- 送货数量 -->
                                                <div class="input-group input-group-sm">
                                                    <input type="number" v-model="list[k].InputOurQty"
                                                    :disabled="Lot_btn"
                                                    :step="item.AllowDecimals ? 'any' : '1'"
                                                    @input="checkDecimalI(k, item)"
                                                    @change="calc_total(k,item)" class="form-control form-control-num"
                                                    value="">
                                                </div>
                                               
                                            </td>
                                            <td>
                                                <div v-if="list[k].RequiredFAI_c != true" >
                                                    <select v-if="!Lot_btn" @change="binNumChange(k,item)" v-model="list[k].WarehouseCode" 
                                                    id="warehousecodeselect" class="form-select myselect myselect3 form-control-theme" :disabled="Lot_btn" :class="{'disabled': Lot_btn}"   data-live-search="true">
                                                        <option v-for="(item,index) in list[k].WareHouseCodeList" :key="index" 
                                                            :value="item.WarehouseCode" :data-name="item.WarehouseCode" :data-tokens="item.WarehouseCode">
                                                            {{item.WarehouseCode}}</option>
                                                    </select>
                                                    <select v-else @change="binNumChange(k,item)" v-model="list[k].WarehouseCode" 
                                                    id="warehousecodeselect" class="form-select myselect myselect5 form-control-theme disabled" :disabled="Lot_btn" :class="{'disabled': Lot_btn}" data-live-search="true">
                                                        <option v-for="(item,index) in list[k].WareHouseCodeList" :key="index" 
                                                            :value="item.WarehouseCode" :data-name="item.WarehouseCode" :data-tokens="item.WarehouseCode">
                                                            {{item.WarehouseCode}}</option>
                                                    </select>
                                                   
                                                </div>
                                                <div v-else>
                                                    <input  type="text" disabled v-model="list[k].WarehouseCode"
                                                    class="form-control form-control-theme">
                                                </div>
                                                <!-- 每箱数量
                                                <div class="input-group input-group-sm">
                                                    <input type="number" v-model="list[k].oneQty"
                                                    :disabled="Lot_btn"
                                                    :step="item.AllowDecimals ? 'any' : '1'"
                                                    @input="checkDecimalO(k, item)"
                                                    @change="calc_total(k,item)" class="form-control form-control-num"
                                                    value="">
                                                </div> -->
                                            </td>
                                            <td>
                                                <div v-if="!list[k].RequiredFAI_c">
                                                    <select v-if="!Lot_btn" data-native-menu="true" @change="numChange(k,item)"   v-model="list[k].BinNum" id="binnumselect"
                                                        class="form-select myselect myselect4 form-control-theme" :disabled="Lot_btn" :class="{'disabled': Lot_btn}"  data-live-search="true">
                                                        <option v-for="(item,index) in list[k].binNumList" :key="index"  :value="item.WhseBin_BinNum" >
                                                            {{item.WhseBin_BinNum}}
                                                        </option>
                                                    </select>
                                                    <select v-else data-native-menu="true" @change="numChange(k,item)"   v-model="list[k].BinNum" id="binnumselect"
                                                        class="form-select myselect myselect5 form-control-theme disabled" :disabled="Lot_btn" :class="{'disabled': Lot_btn}"  data-live-search="true">
                                                        <option v-for="(item,index) in list[k].binNumList" :key="index"  :value="item.WhseBin_BinNum" >
                                                            {{item.WhseBin_BinNum}}
                                                    </option>
                                                    </select>
                                                </div>
                                                <div v-else>
                                                    <input disabled type="text" v-model="list[k].BinNum" class="form-control form-control-theme">
                                                </div>
                                                <!-- 尾箱数量
                                                <div  class="input-group input-group-sm">
                                                    <input type="number" v-model="list[k].tailQty"
                                                    :disabled="Lot_btn"
                                                    :step="item.AllowDecimals ? 'any' : '1'"
                                                    @input="checkDecimal(k, item)"
                                                    @change="calc_total(k,item)" class="form-control form-control-num"
                                                    value="">
                                                </div> -->
                                            </td>
                                            <!-- <td>
                                                总箱数
                                                <div class="input-group input-group-sm">
                                                    <input type="number" v-model="list[k].totalQty" disabled
                                                    
                                                    class="form-control form-control-num" value="">
                                                </div>
                                                
                                            </td> -->

                                        </tr>
                                    </table>
                                    <table class="table mt-0 mb-0 table-buy table-borderless table-sm">
                                        <tr>
                                            <!-- 目标位置 -->
                                            <td  colspan="2" class="pr-2">
                                                <button type="button" tapmode=""
                                                @click="CreateLocation(k,item)"
                                                :disabled="list[k].RequiredFAI_c == true || Lot_btn"
                                                class="btn btn-primary  btn-block">{{lan['To_Location']}}</button>
                                            </td>
                                            <!-- 生成条码 -->
                                            <!-- <td class="pr-2"> <button type="button" tapmode=""
                                                @click="CreateBarCode(k,item)"
                                                :disabled="Lot_btn"
                                                class="btn btn-primary  btn-block">{{lan['Generate_barcode']}} <span
                                                    class="badge badge-light">{{item.tags.length}}</span></button>
                                            </td> -->
                                        </tr>
                                        <tr>
                                            <td colspan="2" class="ttl">{{lan['LotNum']}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <div class="d-flex align-items-center justify-content-center">
                                                    
                                                    <input  type="text" @change="checkLot(k,item)"
                                                        v-model.lazy="list[k].LotNum" :disabled="list[k].is_Lot != 1 || Lot_btn"
                                                        class="form-control form-control-num mr-2" value="">
                                                        <!-- 生成批号按钮 -->
                                                        <button style="width: 120px;"  :disabled="list[k].is_Lot == 2 || Lot_btn" :id="'GetLotNum'+k"
                                                            type="button" @click="GenerateNewLotNum(k,2);"
                                                            class="btn  btn-sm" :class="(list[k].is_Lot == 2 || Lot_btn) ? 'btn-secondary':'btn-primary'"  >{{lan['Generate_lot_number']}}
                                                        </button>
                                                        <!-- 批次属性按钮 -->
                                  
                                                        <button style="margin-left: 3px; width: 120px;"  :disabled="item.BatchProperties" type="button" @click="BatchProperties(item,k);"
                                                            class="btn  btn-sm" :class=" item.BatchProperties ? 'btn-secondary':'btn-primary'">{{lan['Batch_Properties']}}
                                                        </button>
                                                        
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <!-- 生成序号 -->
                                            <td class="pr-2"> 
                                                <button :disabled="list[k].is_SerialNum == 2  || (list[k].SNBaseDataType == 'MASK' && list[k].MaskType == 0) || list[k].SNBaseDataType == 'CHARACTER' || list[k].entryCheck"
                                                @click="CreateSeren(k,item)" type="button" tapmode=""
                                                class="btn btn-primary btn-action  btn-block">{{lan['Generate_SN']}} <span
                                                    class="badge badge-light">{{item.SelectedSerialNumbers.length}}</span></button>
                                            </td>
                                            <!-- 登记序号 -->
                                            <td class="pr-2">
                                                <button type="button" tapmode="" @click="SaveSN(k,item)" :disabled="list[k].is_SerialNum == 2 || (list[k].SNBaseDataType == 'MASK' && list[k].MaskType == 1) || list[k].createCheck"
                                                class="btn btn-primary btn-action  btn-block">{{lan['Save_SN']}}
                                                </button>
                                            </td>
                                        </tr>

                                    </table>

                                </div>
                            </div>
                        </div>


                    </div>
                </div>
                <!-- <div class="scrollable-scrollbar">
                    <div class="scrollable-track"></div>
                    <div class="scrollable-thumb"></div>
                </div> -->
            </div>

        </div>
        <div  class="modal fade" id="printModal" tabindex="-1" aria-labelledby="printModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="printModalLabel">{{lan['Pls_select']}}</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">

                        <div  v-if="checkShow" class="row  align-items-center">
                            <div v-for="(item,k) in list" :key="'cai'+k" v-if="item.shoucai == 2" id="caiitem"
                                class="col-12 col-sm-6 col-md-4">
                                <div class="d-flex bd-highlight align-items-start">
                                    <div class="pt-2 bd-highligh">
                                        <div class="custom-control custom-switch">
                                            <!-- 请选择 -->
                                            <input  type="checkbox" v-model="list[k].print" class="custom-control-input"
                                                :id="'Print'+item.PORel_PONum+'-'+item.PORel_POLine+'-'+item.PORel_PORelNum">
                                            <label class="custom-control-label"
                                                :for="'Print'+item.PORel_PONum+'-'+item.PORel_POLine+'-'+item.PORel_PORelNum"></label>
                                        </div>
                                    </div>
                                    <div class="pt-2 flex-grow-1 bd-highlight">
                                        <table class="table table-buy table-borderless table-sm">
                                            <tr>
                                                <td style="min-width: 80px;" class="ttl">{{lan['No']}}</td>
                                                <td class="ttl">{{lan['Line']}}</td>
                                                <td class="ttl">{{lan['RelNum']}}</td>
                                                <td class="ttl" v-if="item.RcvInspectionReq !=null  && item.RequiredFAI_c == false" style="width: 35px;text-align: center;">{{lan['Inspection']}}</td>
                                                <td class="ttl" v-if="item.RequiredFAI_c != false" style="width: 35px;text-align: center;">FAI</td>
                                            </tr>
                                            <tr>
                                                <td style="min-width: 80px;"> {{item.PORel_PONum}}</td>
                                                <td>{{item.PORel_POLine}}</td>
                                                <td>{{item.PORel_PORelNum}}</td>
                                                <td  v-if="item.RcvInspectionReq !=null  && item.RequiredFAI_c ==false" style="width: 35px;text-align: center;"> <input type="checkbox"  disabled  v-model="item.RcvInspectionReq"/></td>
                                                <td  v-if="faiIns==1 && item.RequiredFAI_c != false" style="width: 35px;text-align: center;"> <input type="checkbox" v-model="item.RequiredFAI_c"   disabled  /></td>
                                            </tr>
                                            <tr>
                                                <td colspan="4"  class="ttl">{{lan['Part']}}</td>
                                            </tr>
                                            <tr>
                                                <td colspan="4">{{item.PODetail_PartNum}}</td>
                                            </tr>
                                            <tr>
                                                <td colspan="4"  class="ttl">{{lan['Desc']}} </td>
                                                
                                            </tr>
                                            <tr>
                                                <td colspan="4">{{item.PODetail_LineDesc}}</td>
                                            </tr>
                                            <tr>
                                                <td style="min-width: 80px;" class="ttl">{{lan['XRelQty']}}</td>
                                                <td class="ttl">{{lan['Received']}}</td>
                                                <td class="ttl">{{lan['Due']}}</td>
                                            </tr>
                                            <tr>
                                                <td style="min-width: 80px;">{{processNumber(item.PORel_XRelQty,item.UOM_NumOfDec)}}<span>{{item.UOM_UOMCode}}</span></td>
                                                <td>{{processNumber(item.PORel_ReceivedQty,item.UOM_NumOfDec)}}<span>{{item.UOM_UOMCode}}</span></td>
                                                <td>{{formatDate(item.PORel_DueDate)}}</td>
                                            </tr>
                                            <tr>
                                                <td class="ttl">{{lan['Job_No']}}</td>
                                            </tr>
                                            <tr>
                                                <td>{{item.PORel_JobNum}}</td>
                                            </tr>
                                        </table>

                                        <table class="table table-buy table-borderless table-sm">
                                            <tr>
                                                <td class="ttl">{{lan['Delivery_QTY']}}</td>
                                            </tr>
                                            <tr>
                                                <td>{{item.InputOurQty}}</td>
                                              
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>


                        </div>


                    </div>
                    <div class="modal-footer">

                        <div style=" flex-flow: row;" class="form-inline">
                            <button type="button" style="width: 100px;" @click="list1_selectall()"
                                class="btn btn-link">{{all1?lan['Un_Select_All']:lan['Select_All']}}</button>
                            <div style="flex: 1;margin-bottom: 0;" class="form-group  mr-3">
                                <label for="staticEmail2" class="sr-only">Label Num</label>
                                <input type="number" :placeholder="lan['Print_Label_Num']" v-model="print_num"
                                    class="form-control" value="">
                            </div>

                            <button type="button" @click="submit()" style="width:80px;"
                                class="btn btn-primary ">{{lan['Print_Label']}}</button>
                        </div>



                    </div>
                </div>
            </div>
        </div>



        <div class="modal fade" id="previewModal" tabindex="-1" aria-labelledby="previewModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="previewModalLabel">Lanel Preview</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">

                        <div class="preview-center">
                            <h3>Label ID</h3>
                            <img class="max" src="../image/label1.png" />
                            <p>PR-2022-99999999</p>

                            <h3>RC Gas Stove</h3>
                            <img class="max" src="../image/label2.png" />
                            <p>011202033012</p>

                            <div class="d-flex justify-content-between align-items-center">
                                <div>Qty: <span>{{print_num}}</span></div>
                                <img class="max1" src="../image/label3.png" />
                            </div>

                        </div>


                    </div>

                </div>
            </div>
        </div>
        <div style="height:60px;"></div>
        <div class="action-row">
            <div class="container">
                <div class=" row ">
                    <div v-show="list.length == 0" id="btn1" class="col-4 col-md-4">
                        <button type="button" @click="showmodal()" :disabled="create_btn" tapmode=""
                            class="btn btn-primary btn-action btn-close">{{lan['New']}}</button>
                    </div>
                    <div id="btn2" class="col-4 col-md-4">
                        <button type="button" tapmode="" :disabled="receipt_btn" onclick="submitfrom();"
                            class="btn btn-primary btn-action btn-submit">{{lan['Confirm']}}</button>
                    </div>

                    <div id="btn3" class="col-4 col-md-4">
                        <button type="button" tapmode="" onclick="openprint();"
                            :disabled="print_btn" class="btn btn-primary btn-action btn-print">{{lan['Print_Label']}}
                        </button>
                    </div>

                    <div v-show="list.length > 0" id="btn4" class="col-4 col-md-4">
                        <button type="button" tapmode="" onclick="cancelClick();"
                            class="btn btn-primary btn-action btn-print">{{lan['Cancel']}}
                        </button>
                    </div>




                </div>

            </div>

        </div>

    </div>

</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/JsBarcode.all.min.js"></script>
<script type="text/javascript" src="../script/qrcode.min.js"></script>
<script type="text/javascript" src="../script/html2canvas.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/iscroll.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<!-- <script type="text/javascript" src="../script/select2/select2.min.js"></script> -->
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/createPoBarcode.js"></script>
<script  type="text/javascript">
    var postcount = 0;
    var returncount = 0;
    var tags = [];
    var tags2 = [];
    var lots = [];
    var lotspostcount = 0;
    var tagspostcount = 0;
    var postlist = [];
    var is_header = 0;
    var row_arr = [];
    var print_tags = [];
    var print_index = 0;
    var subcount = 0;
    var postrows = [];
    var countrys = {};
    var ProdCodes = {};
    
    var is_submit = 0;//是否已提交
    $(document).ready(function() {
        $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
            if (e.target.getAttribute("id") === "profile-tab") {
                // 切换到profile页签后，将滚动条滚动到顶部并显示默认的第一条数据
                document.getElementById('profile').scrollTop = 0;
                document.getElementById('profile').querySelectorAll('#caiitem')[0].scrollIntoView({ behavior: 'auto', block: 'start' });
            }
        });
    });
    const app = new Vue({
        el: '#app',
        data: {
            list: [],
            listids: [],
            polist: [],
            podlist:[],
            screenwidth: document.body.clientWidth,
            vendors: [],
            vendorsList:[],
            WareHouseCodeList:[],
            binNumList:[],
            //已结
            IncludingClosed:false,
            checkShow:true,
            searchdata: {
                name: '',
                PackSlip: '',
                ArrivedDate: timenow(),
                VendorID: '',
                VendorName: '',
                VendorNum: '',
                PONum: '',
                POLine: '',
                PORelNum: '',
                ImportNum:''

            },
            faiIns:0,
            tranType:2,
            uinfo: {},
            label: {},
            //postlist: [],
            postlistids: [],
            create_btn: false,
            receipt_btn: true,
            sn_btn:false,
            confirm_btn:true,
            print_btn: true,
            select_btn:false,
            select_num:0,
            print_sn: false,
            print_barcode: true,
            Lot_btn:false,
            print_num: 1,
            all1: 0,
        },
        watch:{
            IncludingClosed:function(value){
                if(value == true){
                    getPoList()
                }else{
                    loadPoList()
                }
            }
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                })()
            }

            //init_select();
        },
        methods: {
 
            list1_selectall: function () {
                var bl = this.all1 ? false : true;
                for (let i in this.list) {
                    if (this.list[i].shoucai == 2) {
                        this.$set(this.$data.list[i], 'print', bl);
                    }
                }
                this.all1 = bl ? 1 : 0;
            },
            checkDecimal(k, item) {
                let inputValue = this.list[k].tailQty;
                // 将输入值解析为浮点数
                let parsedValue = parseFloat(inputValue);
                // 检查输入是否为空或非数字
                // 如果解析成功，限制小数位数不超过 NumOfDec
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > item.NumOfDec) {
                        // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                        inputValue = inputValue.substring(0, inputValue.indexOf('.') + item.NumOfDec + 1);
                    }
                    item.tailQty = inputValue;
                }
              
            },

            checkDecimalO(k, item) {

                let inputValue = this.list[k].oneQty;
                // 将输入值解析为浮点数
                let parsedValue = parseFloat(inputValue);
                // 检查输入是否为空或非数字
                // 如果解析成功，限制小数位数不超过 NumOfDec
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > item.NumOfDec) {
                        // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                        inputValue = inputValue.substring(0, inputValue.indexOf('.') + item.NumOfDec + 1);
                    }
                    item.oneQty = inputValue;
                } 
            },
            checkDecimalI(k, item) {
                let inputValue = this.list[k].InputOurQty;
                // 将输入值解析为浮点数
                let parsedValue = parseFloat(inputValue);
                // 检查输入是否为空或非数字
                // 如果解析成功，限制小数位数不超过 NumOfDec
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > item.NumOfDec) {
                        // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                        inputValue = inputValue.substring(0, inputValue.indexOf('.') + item.NumOfDec + 1);
                    }
                    item.InputOurQty = inputValue;
                } 
                
            },
            $forceUpdate: function () {  
                this.$forceUpdate();  
            },
            //获取仓位数据
            async getBinNum(index,value){
                let that = this;
                $('.myselect4').selectpicker('destroy'); // 先销毁
                await api.ajax({
                        url: server + 'BaqSvc/WMS_WhseBin/?CompID='+userinfo.Company+'&WarehouseCode='+value,
                        method: 'get',
                        returnAll: false,
                        headers: {
                            'Authorization': userinfo.Token,
                        },
                        data: {}
                }, function(ret, err){
                    if(ret && ret.value){
                        that.$set(that.list[index],'binNumList',ret.value)
                        // that.list[index].binNumList = that.list[index].binNumList.concat(ret.value);
                        console.log(JSON.stringify(that.list[index].binNumList),44444)
                        setTimeout(function () {
                            $('.myselect4').selectpicker('refresh');//在更新
                            $('.myselect4').selectpicker();
                        }, 200);
                    }
                })
            },
            binNumChange(index,item){
                this.getBinNum(index,item.WarehouseCode)
               
            },
            numChange(index,item){
                console.log(JSON.stringify(this.list))
            },
            updateSearch(event){
            },
            handleInput(value){

                value == true ? this.closed_btn = false : this.closed_btn = true

            },
            poNumChange(){
                let that = this
                if(that.searchdata.PONum == ""){
                    that.select_num = 0
                    return
                }
                userinfo = get_user_info();
                var filter = "Company eq '" + userinfo.Company + "'";
                if (that.searchdata.PONum) {
                    filter += " and PONum eq " + that.searchdata.PONum + "";
                }
                if(that.IncludingClosed == false){
                    filter += " and OpenOrder eq true"
                }

                console.log(filter,111111)
                api.ajax({
                    url: server + 'Erp.BO.POSvc/POes',
                    method: 'get',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                    },
                    data: {
                        values: {
                            '$filter': filter
                        }
                    }
                }, function (ret, err) {
                    console.log(JSON.stringify(ret),2222222)
                    hideProgress();
                    if (ret && ret.value.length > 0) {
                       let data = ret.value[0];
                       that.searchdata.VendorID = data.VendorVendorID;
                       that.searchdata.PONum = data.PONum;
                       that.searchdata.VendorNum = parseInt(data.VendorNum);
                       that.searchdata.VendorName = data.VendorName;
                        //    $('#vendorselect').val(that.searchdata.VendorID)
                        //    $('#vendorselect').text(that.searchdata.VendorID)
                        that.select_num = 1
                    getPoList(" and PONum eq " + that.searchdata.PONum + "")
                    $('#vendorselect').val(data.VendorVendorID).trigger("change");
                    


                    }else{
                        api.toast({
                            msg: lan['PO_NO_Model'],
                            location: 'middle'
                        });
                        return
                    }

                });
               
            },
           
            loadPromise(){
                let that = this
                let promises = [];
                console.log(JSON.stringify(userinfo.Company),)
                that.checkShow = false
                console.log(JSON.stringify(that.list.length),555555)
                for (let i = 0; i < that.list.length; i++) {
                    if(that.list[i].shoucai == 2){
                        promises.push(app.getBinNum(i,that.list[i].WarehouseCode))
                    }
                 
                }

                Promise.all(promises).then(function() {
                    console.log(JSON.stringify(that.list),44444)
                    console.log("所有异步请求数据已完成");
                    that.checkShow = true
                });
            },
            submit: function () {
                var btns = [];
                if (this.print_barcode) {
                    btns.push(lan['Print_Carton_Label']);
                }
                if (this.print_sn) {
                    btns.push(lan['Print_SN_Label']);
                }
                var that = this;
                api.actionSheet({
                    title: lan['Tips'],
                    cancelTitle: lan['Cancel'],
                    buttons: btns
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    var key = index - 1;
                    if (btns[key] == lan['Print_Carton_Label']) {
                        that.submit_barcode();
                    }
                    if (btns[key] == lan['Print_SN_Label']) {
                        that.submit_sncode();
                    }
                });
            },

            submit_sncode: function () {
                print_index = 0;
                print_tags = [];
                if (!this.print_num) {
                    api.toast({
                        msg: "請輸入打印數量",
                        location: 'middle'
                    });
                    return false;
                }
                canclick = false;
                for (i in this.list) {
                    if (this.list[i].shoucai == 2) {
                        console.log(JSON.stringify(this.list[i]),111111)
                        if (this.list[i].print) {
                            canclick = true;
                            //执行打印代码
                            var tags1 = this.list[i].SelectedSerialNumbers;
                            var key = "pl" + this.list[i].PORel_PONum + this.list[i].PORel_POLine;
                            for (k in tags1) {
                                print_tags.push(tags1[k]);
                            }

                        }
                    }
                }
                if (!canclick) {
                    api.toast({
                        msg: "Pls Select 收貨行打印標籤",
                        location: 'middle'
                    });
                    return false;
                } else {
                    open_printpage(print_tags,this.print_num,3);

                }

            },
            submit_barcode: function () {
                print_index = 0;
                print_tags = [];
                if (!this.print_num) {
                    api.toast({
                        msg: "請輸入打印數量",
                        location: 'middle'
                    });
                    return false;
                }
                canclick = false;
                for (i in this.list) {
                    if (this.list[i].shoucai == 2) {
                        let tags1 =[]
                        console.log(JSON.stringify(this.list[i]),111111)
                        if (this.list[i].print) {
                            canclick = true;
                            //执行打印代码
                            tags1.push(this.list[i]);
                            this.list[i].WareHouseCodeList = []
                            this.list[i].binNumList = [];
                            var listitem = this.list[i];
                            console.log(JSON.stringify(listitem),22222)
                            console.log(JSON.stringify(tags1),33333)
                            var key = "pl" + this.list[i].PORel_PONum + this.list[i].PORel_POLine;
                            for (k in tags1) {
                                tags1[k].LabelNum =  listitem.PODetail_PartNum + "/" + listitem.LotNum 
                                tags1[k].LotNum = listitem.LotNum;
                                tags1[k].POLine = listitem.PORel_POLine;
                                tags1[k].PORelNum = listitem.PORel_PORelNum;
                                tags1[k].PartNum = listitem.PODetail_PartNum;
                                tags1[k].PONum = listitem.PORel_PONum
                                tags1[k].PartDescription = listitem.PODetail_LineDesc;
                                tags1[k].ProdCode = listitem.ProdCode || "";
                                tags1[k].version = listitem.version || "";
                                tags1[k].POLine = listitem.PORel_POLine || "";
                                tags1[k].is_Lot = listitem.is_Lot;
                                tags1[k].IUM = listitem.UOM_UOMCode;
                                print_tags.push(tags1[k]);
                            }

                        }
                    }
                }
                if (!canclick) {
                    api.toast({
                        msg: "Pls Select 收貨行打印標籤",
                        location: 'middle'
                    });
                    return false;
                } else {
                    let  ExpiryDate = api.getPrefs({
                        sync: true,
                        key:'ExpiryDate'
                    })
                    console.log(JSON.stringify(print_tags),8888)
                    for (i in print_tags) {
                        print_tags[i].ExpiryDate = ExpiryDate;
                        if(print_tags[i].is_Lot == "1" && print_tags[i].LotNum == ""){
                            api.toast({
                                msg:lan['LotNum_placeholder'],
                                location: 'middle'
                            })
                            return
                        }
                    }
                 
                    open_printpage2(print_tags, this.print_num, 1, 1,1);
                   
                   
                    api.removePrefs({key:'ExpiryDate'})
                    //if(ajaxing){return;}showProgress(lan['Loading']);
                    //wificonnect();
                    //startPrint();
                }
                return;
                $('#printModal').modal('hide');
                setTimeout(function () {
                    $('#previewModal').modal('show');
                }, 500);

            },
            //点击批次属性跳转页面
            BatchProperties:function(item,index){
                let that = this
                let PartNum = item.PODetail_PartNum || '';
                let LotNum = item.LotNum || '';
                if(!LotNum){
                    api.toast({
                        msg:lan['Please_Lot_nunber'],
                        location: 'middle'
                    });
                    return
                }
                if(PartNum != '' && LotNum != ''){
                    var data = {};
                    data.item = item;
                    data.PartNum = PartNum;
                    data.LotNum = LotNum;
                    data.index = index;
                    data.attribute_btn = item.attribute_btn
                    data.Lot_btn = app.Lot_btn;
                    data.title = lan['Batch_Properties'];
                    data.frame = "batch_properties";
                    
                    openNavWin2(data.frame, data);
                    app.$set(app.list[index],'BatchCheck',true)
                    if(!this.receipt_btn){
                        that.check_canclick()
                    }
                }
            },
            GenerateNewLotNum: function (index, shoucai) {

                var model = {
                    "vPartNum": this.list[index].PODetail_PartNum
                }
                var that = this;

                api.ajax({
                    url: server + 'Erp.BO.LotSelectUpdateSvc/GenerateNewLotNum',
                    method: 'post',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    data: {
                        body: JSON.stringify(model)
                    }
                }, function (ret, err) {
                    ajaxing = 0;
                    console_debug(ret, err);
                    console.log(JSON.stringify(model),22222)
                    console.log(JSON.stringify(ret),111111)
                    hideProgress();
                    if (ret) {
                        that.$set(that.$data.list[index], 'LotNum', ret.parameters.vNewLotNum);
                        // that.LotSelectUpdate(index);
                    } else {
                        api.toast({
                            msg: lan['TrackLots_Error'],
                            location: 'middle'
                        });
                    }
                    that.check_canclick();

                });


            },
            LotSelectUpdate: function (index) {
                var that = this;
                var item = this.list[index];

                console.log(JSON.stringify(item),33333)
                api.ajax({
                    url: server + 'Erp.BO.LotSelectUpdateSvc/WMS_CheckLotNum/?CompID=' + userinfo.Company + '&PartNum=' + item.PODetail_PartNum + '&LotNum=' + item.LotNum,
                    method: 'get',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    data: {}
                }, function (ret, err) {
                    ajaxing = 0;
                    console.log(JSON.stringify(ret),44444)
                    console.log(JSON.stringify(err),55555)
                    console_debug(ret, err);
                    //hideProgress();
                    if (ret) {
                        that.$set(that.$data.list[index], 'ExpirationDate', ret.ExpirationDate);
                    } else {
                        /*
                        api.toast({
                            msg: lan['TrackLots_Error'],
                            location: 'middle'
                        });
                        */
                    }
                    that.check_canclick();

                });


                },

            toshou: function (index, item) {
                var key = item.PORel_PONum + '-' + item.PORel_POLine
                var i = index;
                $('.myselect3').selectpicker('destroy'); // 先销毁
                console.log(JSON.stringify(userinfo),222222)
                console.log(JSON.stringify(item),111111)
                var shoucai = this.list[i].shoucai == 1 ? 2 : 1;
                console_debug(i, shoucai);
                LotAttributeOption(index,item)
                var that = this;
                var unk = 0;
                if (item.Calculated_ReceivedTo == "PUR-UKN") {
                    unk = 1;
                    that.$set(that.$data.list[i], 'is_Lot', 2);
                    that.$set(that.$data.list[i], 'is_SerialNum', 2);
                }
                if (that.list[i].is_Lot != -1) {
                    setTimeout(function () {
                        that.$set(that.$data.list[i], 'shoucai', shoucai);
                        $('.myselect3').selectpicker('refresh');//在更新
                        $('.myselect3').selectpicker();
                        app.getBinNum(index,item.WarehouseCode)
                    }, 500)
                    return;
                }
               

            },
            checkLot: function (index, item) {

                var that = this;
                api.ajax({
                    url: server + 'BaqSvc/WMS_CheckLotNum/?CompID='+userinfo.Company+'&LotNum='+item.LotNum+'&PartNum='+item.PODetail_PartNum,
                    method: 'get',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    data: {
                    }
                }, function (ret, err) {
                    ajaxing = 0;
                    console_debug(ret, err);
                    if (ret && ret.value && ret.value.length > 0) {
                        that.$set(that.$data.list[i], 'LotNum', "");
                        api.toast({
                            msg: lan['LotNum_Exist'],
                            location: 'middle'
                        });
                        that.check_canclick();
                    } else {
                        that.check_canclick();
                    }

                });
            },
            CreateLocation:function(index,item){
                console.log(JSON.stringify(item),11111)
                console.log(JSON.stringify(index),22222)
                api.ajax({
                    url: server + 'BaqSvc/WMS_LocationWhse/?CompID=' +userinfo.Company +'&POLine='+item.PORel_POLine+'&PONum='+item.PORel_PONum +'&PORelNum='+item.PORel_PORelNum,
                    method: 'get',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    data: { }
                }, function (ret, err) {
                    ajaxing = 0;
                    console.log(JSON.stringify(ret),33333);
                    $('.myselect4').selectpicker('destroy'); // 先销毁
                    $('.myselect3').selectpicker('destroy'); // 先销毁
                    app.$set(app.list[index],"WarehouseCode","")
                    app.$set(app.list[index],"BinNum","")
                    if (ret && ret.value && ret.value.length > 0) {
                        app.$set(app.list[index],"WarehouseCode",ret.value[0].Calculated_WarehouseCode)
                        app.list[index].WarehouseCode = ret.value[0].Calculated_WarehouseCode
                        app.$set(app.list[index],"BinNum",ret.value[0].Calculated_BinNum)
                        app.list[index].BinNum = ret.value[0].Calculated_BinNum
                        setTimeout(function () {
                            $('.myselect3').selectpicker('refresh');//在更新
                            $('.myselect4').selectpicker('refresh');//在更新
                            app.getBinNum(index,ret.value[0].Calculated_WarehouseCode)
                         
                        }, 200);
                        console.log(JSON.stringify(app.list[index]),44444);
                    } 

                });


            },
            CreateBarCode: function (index, item) {
                var InputOurQty = parseInt(item.InputOurQty);
                createPoBarcode(item, index);
                this.$set(this.$data.list[index], 'SelectedSerialNumbers', []);
                this.$set(this.$data.list[index],'createCheck',false)
                this.$set(this.$data.list[index],'entryCheck',false)
                this.$set(this.$data.list[index],'snsCheck',false)

                
            },
            GenerSn:function(index,item){
                return new Promise((resolve, reject) => { 
                    var InputOurQty = 0;
                    var totalOurQty = 0;
                    for(let i=0;i<this.list.length;i++){
                        if(this.list[i].shoucai == 2 && this.list[i].PODetail_PartNum==item.PODetail_PartNum && this.list[i].SelectedSerialNumbers.length !=0){
                            totalOurQty = parseInt(item.InputOurQty) + parseInt(this.list[i].InputOurQty);
                            console.log(InputOurQty,55555)
                        }
                    }
                    if(totalOurQty == 0){
                        InputOurQty = parseInt(item.InputOurQty);
                    }else{
                        InputOurQty = totalOurQty 
                    }
                    // InputOurQty = parseInt(item.InputOurQty);
                    console.log(InputOurQty,1111)
                    if (!item.InputOurQty) {
                        api.toast({
                            msg: lan['Please_enter_Qty'],
                            location: 'middle'
                        });
                        return false;
                    }
                
                    if (ajaxing) { return; } showProgress(lan['Loading']);
                    var PackLine = index + 1;
                    var that = this;
                    var data1 = {
                        "CompanyID": userinfo.Company,
                        "PlantID": userinfo.Site,
                        "UserName": userinfo.Name,
                        "Password": userinfo.password,
                        "Data": { "CompanyID": userinfo.Company, "PlantID": userinfo.Site, "PackSlip": app.searchdata.PackSlip, "PackLine": PackLine, "VendorID": item.VendorID, "PartNum": item.PODetail_PartNum, "IUM": item.IUM, "Qty": InputOurQty,"ImportNum":app.searchdata.ImportNum },
                    }
                    api.ajax({
                        url: wmsserver + 'snporcv/',
                        method: 'post',
                        returnAll: false,
                        headers: {
                            'token': wmstoken,
                            'Content-Type': 'application/json;charset=utf-8'
                        },
                        //dataType: 'text',
                        data: {
                            body: create_submit_data(data1)
                        }
                        //data: {values: data1}
                    }, function (ret, err) {
                        ajaxing = 0;
                        console_debug(ret, err);
                        hideProgress();
                        if (ret && ret.code == 1) {
                            var count = item.totalQty;
                            var oneQty = parseInt(item.oneQty);
                            var snno =[]
                            var SerialNumbers=[]
                            if(totalOurQty == 0){
                                snno = ret.data.SelectedSerialNumbers;
                            }else{
                                let SelectedSerialNumbers = ret.data.SelectedSerialNumbers;
                                // 遍历SelectedSerialNumbers数组
                                for (let i = 0; i < SelectedSerialNumbers.length; i++) {
                                    let serialNumber = SelectedSerialNumbers[i];

                                    // 检查serialNumber是否存在于list中的任何SelectedSerialNumbers中
                                    let found = false;
                                    for (let j = 0; j < that.list.length; j++) {
                                        let listSerialNumbers = that.list[j].SelectedSerialNumbers;
                                        for (let k = 0; k < listSerialNumbers.length; k++) {
                                        if (listSerialNumbers[k].SerialNumber === serialNumber.SerialNumber) {
                                            found = true;
                                            break;
                                        }
                                        }
                                        if (found) {
                                        break;
                                        }
                                    }

                                    // 如果未找到匹配项，则将该serialNumber添加到filteredSerialNumbers中
                                    if (!found) {
                                        snno.push(serialNumber);
                                    }
                                }
                            
                            }
                        
                            var k = 1;
                            for(i in snno){
                                if (k == count) {
                                    snno[i].OnhandQty = item.tailQty ? item.tailQty : item.oneQty; //数量
                                } else {
                                    snno[i].OnhandQty = item.oneQty; //数量
                                }
                                
                                var tag = item.tags[k - 1];
                                // tag.ExpiryDate = item.ExpirationDate;
                                snno[i]['xs'] = k;
                                snno[i]['type'] = 1;
                                snno[i]['tag'] = tag;
                                snno[i].SerialNumber ="";
                                snno[i].SNBaseNumber ="";
                                snno[i].RawSerialNum ="";
                                var i1 = parseInt(i) + 1;
                                if (i1 % oneQty == 0) {
                                    k++;
                                }
                            }
                            console_debug(snno, 'SelectedSerialNumbers');
                            console.log(JSON.stringify(snno),8888888)
                            that.$set(that.$data.list[index], 'SelectedSerialNumbers', snno);
                            that.$set(that.$data.list[index],'createCheck',true)
                            resolve();
                        } else {
                            that.$set(that.$data.list[index],'createCheck',false)
                            errMassage(ret.msg)
                            hideProgress();
                        }

                    });
                })

            },
            CreateSeren: function(index,item){
                console.log(JSON.stringify(item),111111)
                console.log(JSON.stringify(item.SelectedSerialNumbers),222222)
                console.log(JSON.stringify(item.SelectedSerialNumbers.length),333333)
                console.log(this.confirm_btn,55555)
                if(!this.confirm_btn){
                    console.log(this.confirm_btn,66666)
                    var data = {};
                    var oneQty = parseInt(item.oneQty);
                    var k = 1;
                    for(i in item.SelectedSerialNumbers){
                        var tag = item.tags[k - 1];
                        item.SelectedSerialNumbers[i]['xs'] = k;
                        item.SelectedSerialNumbers[i]['type'] = 1;
                        item.SelectedSerialNumbers[i]['tag'] = tag;
                        var i1 = parseInt(i) + 1;
                        if (i1 % oneQty == 0) {
                            k++;
                        }
                    }
                    var arr = [];
                    arr.push(item)
                    data.list = arr;
                    data.key = index;
                    data.title = lan['Generate_SN'];
                    data.receipt_btn = this.sn_btn;
                    data.SNFormat = item.SNFormat;
                    data.SNPrefix = item.SNPrefix;
                    data.createCheck = item.createCheck;
                    data.entryCheck = item.entryCheck;
                    data.SNBaseDataType = item.SNBaseDataType;
                    data.MaskType = item.MaskType;
                    data.frame = "save_sn";
                    openNavWin2(data.frame, data);
                }else{
                    console.log(this.confirm_btn,77777)
                    if(item.SelectedSerialNumbers.length == 0){
                        this.CreateSn(index,item)
                    }else{
                        var data = {};
                        var oneQty = parseInt(item.oneQty);
                        var k = 1;
                        for(i in item.SelectedSerialNumbers){
                            var tag = item.tags[k - 1];
                            item.SelectedSerialNumbers[i]['xs'] = k;
                            item.SelectedSerialNumbers[i]['type'] = 1;
                            item.SelectedSerialNumbers[i]['tag'] = tag;
                            var i1 = parseInt(i) + 1;
                            if (i1 % oneQty == 0) {
                                k++;
                            }
                        }
                        var arr = [];
                        arr.push(item)
                        data.list = arr;
                        data.key = index;
                        data.title = lan['Generate_SN'];
                        data.receipt_btn = this.sn_btn;
                        data.SNFormat = item.SNFormat;
                        data.SNPrefix = item.SNPrefix;
                        data.createCheck = item.createCheck;
                        data.entryCheck = item.entryCheck;
                        data.SNBaseDataType = item.SNBaseDataType;
                        data.MaskType = item.MaskType;
                        data.frame = "save_sn";
                        openNavWin2(data.frame, data);
                    }
                }
               
            },
            CreateSn: function (index, item) {
                var InputOurQty = 0;
                var totalOurQty = 0;
                for(let i=0;i<this.list.length;i++){
                    if(this.list[i].shoucai == 2 && this.list[i].PODetail_PartNum==item.PODetail_PartNum && this.list[i].SelectedSerialNumbers.length !=0){
                        totalOurQty = parseInt(item.InputOurQty) + parseInt(this.list[i].InputOurQty);
                        console.log(InputOurQty,55555)
                    }
                }
                if(totalOurQty == 0){
                    InputOurQty = parseInt(item.InputOurQty);
                }else{
                    InputOurQty = totalOurQty 
                }
                // InputOurQty = parseInt(item.InputOurQty);
                console.log(InputOurQty,1111)
                if (!item.InputOurQty) {
                    api.toast({
                        msg: lan['Please_enter_Qty'],
                        location: 'middle'
                    });
                    return false;
                }

                if (ajaxing) { return; } showProgress(lan['Loading']);
                var PackLine = index + 1;
                var that = this;
                var data1 = {
                    "CompanyID": userinfo.Company,
                    "PlantID": userinfo.Site,
                    "UserName": userinfo.Name,
                    "Password": userinfo.password,
                    "Data": { "CompanyID": userinfo.Company, "PlantID": userinfo.Site, "PackSlip": app.searchdata.PackSlip, "PackLine": PackLine, "VendorID": item.Vendor_VendorID, "PartNum": item.PODetail_PartNum, "IUM": item.UOM_UOMCode, "Qty": InputOurQty,"ImportNum":app.searchdata.ImportNum },
                }
                api.ajax({
                    url: wmsserver + 'snporcv/',
                    method: 'post',
                    returnAll: false,
                    headers: {
                        'token': wmstoken,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    //dataType: 'text',
                    data: {
                        body: create_submit_data(data1)
                    }
                    //data: {values: data1}
                }, function (ret, err) {
                    ajaxing = 0;
                    console_debug(ret, err);
                    hideProgress();
                    if (ret && ret.code == 1) {
                        var count = item.totalQty;
                        var oneQty = parseInt(item.oneQty);
                        that.$set(that.$data.list[index], 'createCheck', true);
                        var snno =[]
                        var SerialNumbers=[]
                        if(totalOurQty == 0){
                            snno = ret.data.SelectedSerialNumbers;
                        }else{
                            let SelectedSerialNumbers = ret.data.SelectedSerialNumbers;
                            // 遍历SelectedSerialNumbers数组
                            for (let i = 0; i < SelectedSerialNumbers.length; i++) {
                                let serialNumber = SelectedSerialNumbers[i];

                                // 检查serialNumber是否存在于list中的任何SelectedSerialNumbers中
                                let found = false;
                                for (let j = 0; j < that.list.length; j++) {
                                    let listSerialNumbers = that.list[j].SelectedSerialNumbers;
                                    for (let k = 0; k < listSerialNumbers.length; k++) {
                                    if (listSerialNumbers[k].SerialNumber === serialNumber.SerialNumber) {
                                        found = true;
                                        break;
                                    }
                                    }
                                    if (found) {
                                    break;
                                    }
                                }

                                // 如果未找到匹配项，则将该serialNumber添加到filteredSerialNumbers中
                                if (!found) {
                                    snno.push(serialNumber);
                                }
                            }
                          
                        }
                       
                        var k = 1;
                        for(i in snno){
                                if (k == count) {
                                   snno[i].OnhandQty = item.tailQty ? item.tailQty : item.oneQty; //数量
                                } else {
                                    snno[i].OnhandQty = item.oneQty; //数量
                                }
                                // tag.ExpiryDate = item.ExpirationDate;
                                snno[i]['xs'] = k;
                                snno[i]['type'] = 1;
                                var i1 = parseInt(i) + 1;
                                if (i1 % oneQty == 0) {
                                    k++;
                                }
                        }
                        console_debug(snno, 'SelectedSerialNumbers');
                        console.log(JSON.stringify(snno),8888888)
                        that.$set(that.$data.list[index], 'SelectedSerialNumbers', snno);
                        that.$set(that.$data.list[index],'createCheck',true)

                        that.print_sn = true;
                        setTimeout(function(){
                            var data = {};
                            var arr = [];
                            arr.push(that.list[index])
                            console.log(JSON.stringify(arr),22222)
                            data.list = arr;
                            data.key = index;
                            data.title = lan['Generate_SN'];
                            data.receipt_btn = this.sn_btn;
                            data.SNFormat = that.list[index].SNFormat;
                            data.SNPrefix = that.list[index].SNPrefix;
                            data.createCheck = that.list[index].createCheck;
                            data.confirm_btn = app.confirm_btn
                            data.entryCheck = that.list[index].entryCheck;
                            data.SNBaseDataType = that.list[index].SNBaseDataType;
                            data.MaskType = that.list[index].MaskType;
                            data.frame = "save_sn";
                        
                            openNavWin2(data.frame, data);
                        },200)
                     
                    } else {
                        hideProgress();
                        that.$set(that.$data.list[index], 'createCheck', false);
                        errMassage(ret.msg)
                    }

                });

            },
            check_canclick: function () {
                var canclick = false;
                var tc = false;
                var sr = false;
                var tg = false;
                var sc = true;
                for (i in this.list) {
                    if (this.list[i].shoucai == 2) {
                        if(this.list[i].InputOurQty == ""){
                            tg = true;
                        }
                        if (this.list[i].is_SerialNum == 1) {
                            console.log(this.receipt_btn,22222)
                            if (!this.list[i].SelectedSerialNumbers || this.list[i].tags.SelectedSerialNumbers == 0) {
                                console.log(this.receipt_btn,33333)
                                sr = true;
                            }
                        }
                        if (this.list[i].is_Lot == 1) {
                            if (!this.list[i].LotNum || this.list[i].LotNum == '') {
                                tc = true;
                            }
                        }
                        sc = false;
                    }

                }
                console.log(tc,111111)
                console.log(tg,333333)
                console.log(sc,333333)
                console.log(sr,444444)
                if (tc  || tg  || sc || sr) {
                    canclick = true;
                }

                this.receipt_btn = canclick;
                console.log(this.receipt_btn,11111)
            },
            calc_total: function (index, item) {
                var InputOurQty = processNumber(this.list[index].InputOurQty,item.NumOfDec) ? processNumber(this.list[index].InputOurQty,item.NumOfDec) : 0;
                var oneQty = 0
                var tailQty =0
                var xiang = 0; 
                if (InputOurQty && oneQty) {
                    var totalQty = Math.ceil(InputOurQty / oneQty);
                    tailQty = processNumber(InputOurQty % oneQty,item.NumOfDec) ;
                    this.$set(this.$data.list[index], 'tailQty', tailQty);
                }
                this.$set(this.$data.list[index], 'totalQty', totalQty);
                this.$set(this.$data.list[index], 'tags', []);
                this.$set(this.$data.list[index], 'SelectedSerialNumbers', []);



                this.check_canclick();

            },
          
            showmodal: function () {
                if (this.screenwidth < 576) {
                    $('#exampleModal').modal('show');
                    init_select();
                } else {

                    $('#PackSlip').focus();
                }
            },
            SaveSN(k,item) {

                console.log(JSON.stringify(item),88888)
                console.log(JSON.stringify(k),999999)
                var data = {};
                var arr = [];
                this.$set(this.$data.list[k], 'entryCheck', true);
                if(item.SelectedSerialNumbers.length != 0){
                    arr.push(item)
                    data.list = arr;
                    data.key = k;
                    data.title = lan['Save_SN'];
                    data.right = [{
                        text: lan["Scan"],
                        color: '#fff',
                    }];
                    var k1 = 1;
                    for(i in item.SelectedSerialNumbers){
                        item.SelectedSerialNumbers[i]['xs'] = k1;
                        var i1 = parseInt(i) + 1;
                        if (i1 % oneQty == 0) {
                            k1++;
                        }
                    }
                    data.receipt_btn = this.sn_btn;
                    data.SNFormat = item.SNFormat;
                    data.SNPrefix = item.SNPrefix;
                    data.createCheck = item.createCheck;
                    data.entryCheck = item.entryCheck;
                    data.SNBaseDataType = item.SNBaseDataType;
                    data.MaskType = item.MaskType;
                    data.PackLine = PackLine;
                    data.confirm_btn = app.confirm_btn
                    data.ImportNum = app.searchdata.ImportNum
                    data.frame = "save_sn";
                    data.PackSlip = app.searchdata.PackSlip
                    openNavWin2(data.frame, data);
                }else{
                    if(!app.confirm_btn || item.snsCheck){
                        var oneQty = parseInt(item.oneQty);
                        var k1 = 1;
                        for(i in item.SelectedSerialNumbers){
                            var tag = item.tags[k1 - 1];
                            // tag.ExpiryDate = item.ExpirationDate;
                            item.SelectedSerialNumbers[i]['xs'] = k1;
                            item.SelectedSerialNumbers[i]['type'] = 1;
                            item.SelectedSerialNumbers[i]['tag'] = tag;
                            var i1 = parseInt(i) + 1;
                            if (i1 % oneQty == 0) {
                                k1++;
                            }
                        }
                        arr.push(item)
                        console.log(JSON.stringify(arr),22222)
                        data.list = arr;
                        data.key = k;
                        data.title = lan['Save_SN'];
                        data.receipt_btn = this.sn_btn;
                        data.SNFormat = item.SNFormat;
                        data.SNPrefix = item.SNPrefix;
                        data.createCheck = item.createCheck;
                        data.confirm_btn = app.confirm_btn
                        data.entryCheck = item.entryCheck;
                        data.PackLine = PackLine;
                        data.PackSlip = app.searchdata.PackSlip
                        data.SNBaseDataType = item.SNBaseDataType;
                        data.MaskType = item.MaskType;
                        data.frame = "save_sn";
                        openNavWin2(data.frame, data);

                    }else{
                        item.SelectedSerialNumbers=[]
                        // if((item.SNBaseDataType == "MASK" && item.MaskType== 0) || item.SNBaseDataType == 'CHARACTER' ){
                        if (!item.InputOurQty) {
                            api.toast({
                                msg: lan['Please_enter_Qty'],
                                location: 'middle'
                            });
                            return false;
                        }
                   
                        var count = item.totalQty;
                        var PackLine = k + 1
                        var oneQty = parseInt(item.oneQty);
                        var k1 = 1;
                        for(let i=0;i<item.InputOurQty;i++){
                            let OnhandQty = 0
                            if (k1 == count) {
                                OnhandQty = item.tailQty ? item.tailQty : item.oneQty; //数量
                            } else {
                                OnhandQty = item.oneQty; //数量
                            }
                            var tag = item.tags[k1 - 1];
                            // tag.ExpiryDate = item.ExpirationDate;
                            item.SelectedSerialNumbers.push({
                                'xs':k1,
                                'type':1,
                                'tag':tag,
                                'OnhandQty':OnhandQty,
                                'SerialNumber':'',
                                'SNBaseNumber':'',
                                'RawSerialNum':''
                            })
                            var i1 = parseInt(i) + 1;
                            if (i1 % oneQty == 0) {
                                k1++;
                            }
                        }
                        arr.push(item)
                        console.log(JSON.stringify(item),444444)
                        data.list = arr;
                        data.key = k;
                        data.title = lan['Save_SN'];
                        data.right = [{
                            text: lan["Scan"],
                            color: '#fff',
                        }];
                        data.receipt_btn = this.sn_btn;
                        data.SNFormat = item.SNFormat;
                        data.SNPrefix = item.SNPrefix;
                        data.createCheck = item.createCheck;
                        data.entryCheck = item.entryCheck;
                        data.SNBaseDataType = item.SNBaseDataType;
                        data.MaskType = item.MaskType;
                        data.PackLine = PackLine;
                        data.confirm_btn = app.confirm_btn
                        data.ImportNum = app.searchdata.ImportNum
                        data.frame = "save_sn";
                        data.PackSlip = app.searchdata.PackSlip
                        openNavWin2(data.frame, data);
                    
                    }
                    
                }
              
            }
        }
    });
    apiready = function () {
        api.parseTapmode();
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if (ret.type == 'left') { 
                if(shouldShowExitConfirmation(app.list)){
                    close_win1();
                }else{
                    close_win();
                }
                
               
            }
            if (ret.type == 'right') { scan(); }

        });
        let  ExpiryDate = api.getPrefs({
            sync: true,
            key:'ExpiryDate'
        })
        server = getapi();
        app.vendorsList = get_prefs_data("Vendors")
        app.vendors = get_prefs_data("Vendors")
        console.log(JSON.stringify(app.vendors),111111)
        app.uinfo = get_user_info();
        userinfo = get_user_info();
        app.searchdata.name = userinfo.Name;
        console_debug(app.vendors, userinfo);
        if (app.screenwidth >= 576) {
            setTimeout(function () {
                init_select();
            }, 500)
        }
        // loadVendor()
        app.WareHouseCodeList = []
        let  parseData = api.getPrefs({
            sync: true,
            key:'WarehouseCode'
        })
        app.WareHouseCodeList = JSON.parse(parseData)
        loadWarehouseCodeData()
        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            
            if(shouldShowExitConfirmation(app.list)){
                close_win1();
            }else{
                close_win();
            }
            
            

        });
        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            if (ret && ret.value && ret.value.str) {
                var val1 = $("input:focus").val();
                val1 = val1 ? val1 : '';
                val1 = val1 + ret.value.str;
                $("input:focus").val(val1);
                get_code_data(ret.value.str);
            }

        });
        api.addEventListener({
            name: 'sn_update'
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret && ret.value) {
                var snposts1 = ret.value;
                snposts = JSON.parse(snposts1);
                console.log(JSON.stringify(snposts),111111)
                console.log(JSON.stringify(app.listids),2222222)
                for (i in snposts) {
                    var key = snposts[i].PORel_PONum + '-' + snposts[i].PORel_POLine + '-' + snposts[i].PORel_PORelNum;
                    var index = $.inArray(key, app.listids);
                    console_debug(key, index);
                    app.list.splice(index,1,snposts[i]);
                    //app.list[index] = snposts[i];
                    
                }
                app.check_canclick()
                api.closeWin({ name: 'save_sn' });
            }
            console_debug(app.list,'');
        });
        api.addEventListener({
            name: 'batch_properties_update'
        }, function (ret, err) {
            if (ret && ret.value) {
                var snposts1 = ret.value;
                console.log(JSON.stringify(snposts1), 55555)
                app.Lot_btn = snposts1.Lot_btn
                app.$set(app.$data.list[snposts1.index],'attribute_btn',snposts1.attribute_btn)
                api.closeWin({ name: 'batch_properties' });
                console.log(JSON.stringify(app.list),66666)
            }
        });



    }
    function cancelClick(){
        if(shouldShowExitConfirmation(app.list)){
            close_win1();
        }else{
            close_win();
        }
    }
    // 检查条件的函数
    function shouldShowExitConfirmation(data) {
        for (let i = 0; i < data.length; i++) {
            const item = data[i];
            if (item.shoucai === 2 && (item.InputOurQty !== "" || item.oneQty !== "" || item.tailQty !== "" || item.totalQty !== "")) {
                return true; // 满足条件，需要弹出确认框
            }
        }
        return false; // 所有对象都不满足条件，无需弹出确认框
    }
   // 执行退出确认逻辑的函数
    function executeExitConfirmation(data, index, callback) {
        if (index < data.length) {
            var obj = data[index];
            // 判断shoucai字段是否等于2且tags数组长度为0
            if (obj.shoucai === 2 && obj.tags.length === 0) {
                // 弹出生成条码弹框
                api.toast({
                    msg: lan['Label_placeholder'],
                    location: 'middle'
                });
                return;
            }

            // 判断is_SerialNum字段是否等于1且SelectedSerialNumbers数组长度为0
            if (obj.is_SerialNum === 1 && obj.SelectedSerialNumbers.length === 0) {
                // 弹出生成序号弹框
                api.toast({
                    msg: lan['Serialnum_placeholder'],
                    location: 'middle'
                });
                return;
            }
           
            // 判断is_Lot字段是否等于1且LotNum为空
            if (obj.is_Lot === 1 && obj.LotNum === "") {
                // 弹出生成批号弹框
                api.toast({
                    msg: lan['Lotnum_placeholder'],
                    location: 'middle'
                });
                return;
            }
            // 判断BatchProperties是否为true
            if(obj.BatchProperties == false){
                // 弹出填写批次属性弹框
                api.toast({
                    msg: lan['Lot_Attribute_placeholder'],
                    location: 'middle'
                });
                return;
            }

            // 继续检查下一个对象
            executeExitConfirmation(data, index + 1, callback);
        } else {
            // 所有对象都已经检查完毕，执行回调函数
            if (typeof callback === "function") {
                callback();
            }
        }
    }
    function loadWarehouseCodeData() {
        userinfo = get_user_info();
        if (!userinfo.Token) {
        return;
        }
        api.ajax({
        url: server + 'Erp.BO.WarehseSvc/List',
        method: 'get',
        returnAll: false,
        headers: {
            'Authorization': userinfo.Token,
        },
        data: {
            values: {
            '$select': 'WarehouseCode,Description,Plant',
            '$filter': "Company eq '" + userinfo.Company + "' and Plant eq '" + userinfo.Site + "'"
            }
        }
        }, function (ret, err) {
            if(ret && ret.value.length>0){
                app.WareHouseCodeList = ret.value
            }
            

        });
    }
  

    //关闭取消事件
    function close_win1() {
        var msg = app.receipt_btn && app.list.length != 0 ? lan['Pur_C_cancel_tips'] : lan['Pur_C_cancel_tips'];
        if (app.confirm_btn && app.list.length != 0) {
            api.confirm({
                title: lan['Tips'],
                msg: msg,
                buttons: [lan['NO'], lan['YES'], lan['Cancel']]
            }, function (ret, err) {
                var index = ret.buttonIndex;
                if (index == 2) {
                    executeExitConfirmation(app.list,0,submitfrom)
                } else if (index == 1) {
                    close_win();
                    app.Lot_btn = false;
                }
            });
        }else{
            close_win();
        }

    }
   
    
    function scan() {
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    get_code_data(ret.content);
                }

            } else {

            }
        });
    }
    //PO数量提示
    function PoQuantityNum(item) {
        return new Promise((resolve, reject) => {
            api.ajax({
                url: server + 'BaqSvc/WMS_LastOprFinishQty/?CompID=' + userinfo.Company + '&AssemblySeq=' + item.AssemblySeq + '&JobNum=' + item.JobNum + '&JobSeq=' + item.JobSeq,
                method: 'get',
                returnAll: false,
                headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
                },
                data: {}
            }, function (ret, err) {
                if (ret && ret.value.length > 0) {
                    let CalculatedQty = ret.value[0].Calculated_Quantity;
                    console.log(CalculatedQty,66666)
                    if (parseInt(item.InputOurQty) > parseInt(CalculatedQty)) {
                        resolve(true); // 如果大于，则执行resolve函数并返回true
                    } else {
                        resolve(null); // 如果不大于，则执行resolve函数并返回null
                    }
                } else {
                    resolve(null);  // 如果请求出错，则执行reject函数
                }
            });
        });
    }
    function get_code_data(content) {
        var arr = content.split("#");
        // alert(JSON.stringify(arr),111111)
        if (arr[0]) {
            //alert(content);
            var row = {};
            row.PONum = arr[2];
            row.VendorNum = '';
            row.OrderNum = '';
            var arr1 = [];
            arr1.push(row);
            app.polist = [];
            app.polist = app.polist.concat(arr1);
            app.searchdata.PackSlip = arr[0];
            app.searchdata.ArrivedDate = timenow();
            app.searchdata.VendorID = arr[1];

            app.searchdata.POLine = arr[3];
            app.searchdata.PORelNum = arr[4];
            //app.polist.push(row);
            if(arr.length == 1){
                app.searchdata.PONum = arr[0];
            }else{
                app.searchdata.PONum = arr[2];
            }
            setTimeout(function () {
                //$('.myselect2').selectpicker('refresh');
                //$('.myselect2').selectpicker('val', arr[0]);
                $('.myselect1').selectpicker('val', arr[1]);
                loadData(1);
            }, 300);
        }
    }



    function wificonnect() {

        var param = get_prefs_data("dyparam");
        if (!param) {
            api.toast({
                msg: lan['Printer_Parameters_placeholder'],
                location: 'middle'
            });
            return false;
        }


        var jsfun = 'wificonnect("' + param.ip1 + '",' + param.port1 + ');';
        alert("Confirm to print");
        api.execScript({
            name: 'root',
            script: jsfun
        });




    }

    function shareapp2() {

        $("#mylabel2").attr("class", "mylabel2 mylbshow");
        $("#mylabel2").trigger("click");
        window.pageYOffset = 0;
        document.documentElement.scrollTop = 0
        document.body.scrollTop = 0


        html2canvas(document.querySelector("#mylabel2")).then(function (canvas) {

            var bsimg = convertCanvasToImage(canvas);
            var k = bsimg.replace(/^.*?,/, '');
            var param = {};
            $("#mylabel2").attr("class", "mylabel2");
            param.bsimg = k;
            wifiprint(2, k, app.print_num)

        });



    }


    function convertCanvasToImage(canvas) {
        var image = new Image();
        image.src = canvas.toDataURL("image/jpg");
        return image.src;
    }



    function wifiprint(type, imgstr, num) {

        var moduleTsc = api.require('moduleTsc');
        moduleTsc.print({ "type": type, "imgstr": imgstr, "print_num": num }, function (ret, err) {
            if (ret) {
                if (ret.status == 1) {
                    var ol = print_tags[print_index];
                    print_index++;
                    if (!print_tags[print_index]) {
                        hideProgress();
                        api.alert({
                            title: 'Tips',
                            msg: '成功发送打印指令',
                        }, function (ret, err) {

                        });
                    }

                } else {
                    hideProgress();
                    errMassage(ret.msg)
                }
            }
        });
    }



    function openprint() {
        $('#printModal').modal('show');
    }

    function getPoList(data){
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        var filter = "ApprovalStatus eq 'A' and Company eq'" + userinfo.Company + "'";
        filter +=" and VendorNum eq " + app.searchdata.VendorNum; 
        if(data != undefined){
            filter += data
        }
        api.ajax({
            url: server + 'Erp.BO.POSvc/List',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },

            data: {
                values: {
                    '$select': 'PONum,OrderNum,VendorNum,OpenOrder',
                    '$filter': filter,
                    '$top':1000,
                }
            }
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                app.polist = [];
                app.polist = app.polist.concat(ret.value);
                setTimeout(function () {
                    $('.myselect2').selectpicker('refresh');
                    //app.searchdata.PONum = arr[2]; = arr[2];
                    if (app.searchdata.PONum) {
                        $('.myselect2').selectpicker('val', app.searchdata.PONum);
                    }
                }, 200);
            }

        });
    }
 
    function loadPoList() {
        let data= " and OpenOrder eq true "
        getPoList(data)
    }


    function init_select() {
        $('.myselect1').selectpicker();
        $('.myselect2').selectpicker();
    }
    
    function getvendorName(ob) {
        console_debug(app.searchdata);
        var vname = $('#vendorselect option:selected').attr("data-name");
        app.searchdata.VendorNum = $('#vendorselect option:selected').attr("data-num");
        app.searchdata.VendorNum = parseInt(app.searchdata.VendorNum);
        if(app.searchdata.VendorID != "" && app.searchdata.VendorID != null && app.select_num == 0){
            app.select_btn = true
        }
        app.searchdata.VendorName = vname;
        if(app.IncludingClosed == false){
            loadPoList();
        }else{
            if(app.searchdata.PONum == ""){
                getPoList()
            }else{
                getPoList(" and PONum eq " + app.searchdata.PONum + "") 
            }
        }
    }


    function submitLotNum() {
        console.log(JSON.stringify(postlist),22222)
        lots = [];
        lotspostcount = 0;
        for (i in postlist) {
            if (postlist[i].is_Lot == 1) {
                lots.push(postlist[i]);
            }
        }
        console.log(JSON.stringify(lots),11111)
        if (lots.length == 0) {
            submitepicor();
        } else {
            for (i in lots) {
                GetNewPartLot(lots[i], i);
            }
        }

    }

    function GetNewPartLot(item, i) {
        console.log(JSON.stringify(item),111111)
        var model = get_partLot_model();
        model.partNum = item.PODetail_PartNum;
        model.ds.PartLot[0].Company = userinfo.Company;
        model.ds.PartLot[0].PartNum = item.PODetail_PartNum;
        model.ds.PartLot[0].LotNum = item.LotNum;
        model.ds.PartLot[0].PartLotDescription = item.LotNum;
        console_debug(model, 'GetNewPartLot提交');


        api.ajax({
            url: server + 'Erp.BO.LotSelectUpdateSvc/GetNewPartLot',
            method: 'post',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: JSON.stringify(model)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, 'GetNewPartLot返回');
            if (ret) {
                var data1 = get_partLot_model2();
                data1.ds.PartLot[0] = ret.parameters.ds.PartLot[1];
                data1.ds.PartLot[0].LotNum = item.LotNum;
                data1.ds.PartLot[0].PartLotDescription = item.LotNum;
                if(item.BatchProperties == true){
                    console.log(222222)
                    UpdateNewPartLot(data1);
                }else{
                    let params ={
                        PartNum:item.PODetail_PartNum,
                        LotNum:item.LotNum
                    }
                    PartLotAttribute(params)
                }

            } else {
                hideProgress();
                api.toast({
                    msg: lan['GetNewPartLot_Submit_Failed'],
                    location: 'middle'
                });
            }

        });




    }
    //批次属性查询接口
    function PartLotAttribute(data){
        let that = this
        api.ajax({
            url: server + 'BaqSvc/WMS_PartLotAttribute/?CompID='+userinfo.Company +'&PartNum='+data.PartNum+'&LotNum='+data.LotNum,
            method:'get',
            returnAll:false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function(ret, err){
            console.log(JSON.stringify(ret),99999)
            if(ret && ret.value.length > 0){
                submitepicor();
            }else{
                hideProgress();
                api.toast({
                    msg:lan['Batch_Properties_placeholder'],
                    location: 'middle'
                })
            }
        })
    }
    function UpdateNewPartLot(data1) {

        console_debug(data1, 'UpdateNewPartLot提交');


        api.ajax({
            url: server + 'Erp.BO.LotSelectUpdateSvc/Update',
            method: 'post',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {
                body: JSON.stringify(data1)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console.log(JSON.stringify(err),'UpdateNewPartLot失败')
            console_debug(ret, 'UpdateNewPartLot返回');
            lotspostcount++;


            if (ret) {
                console.log(JSON.stringify(lotspostcount),22222)
                if (lotspostcount == lots.length) {
                    submitepicor();
                }

            } else {
                app.receipt_btn = true
                hideProgress();
                api.toast({
                    msg: lan['GetNewPartLot_Submit_Failed'],
                    location: 'middle'
                });
            }

        });




    }

    //确认事件
    function submitfrom() {
        postlist = [];
        tags = [];
        tags2 = [];
        var d = new Date();
        var t = d.getTime();
        var no = 0;
        for (i in app.list) {
            //app.list[i].Date01 = param.Date01;
            if (app.list[i].shoucai == 2) {
                if (app.list[i].is_SerialNum === 1 && app.list[i].SelectedSerialNumbers.length === 0) {
                    // 弹出生成序号弹框
                    api.toast({
                        msg: lan['Serialnum_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                if(!app.list[i].attribute_btn && !app.list[i].BatchProperties){
                    api.toast({
                        msg: lan['Lot_Attribute_placeholder'],
                        location: 'middle'
                    });
                    hideProgress();
                    return false; 
                }

                if(!app.list[i].BinNum){
                    // 弹出生成序号弹框
                    api.toast({
                        msg:app.list[i].PODetail_PartNum + lan['BN_placeholder'],
                        location: 'middle'

                    })
                    return;
                }
                var row ={};
                var row2 = get_transaction_model();
                row.Company = userinfo.Company;
                row.PlantID = userinfo.Site;
                row.UserName = userinfo.UserName;
                row.Password = userinfo.Password;
                row.PartNum = app.list[i].PODetail_PartNum; //物料编号
                row.PartDescription = app.list[i].PODetail_LineDesc; //物料编号
                row.LotNum = app.list[i].LotNum; //批号
                row.WarehouseCode = app.list[i].WarehouseCode;
                row.BinNum = app.list[i].BinNum;
                row.Vendor_VendorID = app.list[i].BinNum;
                row.Received = app.list[i].Received;
                row.ReceiptDate = app.searchdata.ArrivedDate;
                if(app.searchdata.ImportNum){
                    row.ImportNum = app.searchdata.ImportNum;
                }
                row.OurQty = app.list[i].InputOurQty;
                row.PONum = app.list[i].PORel_PONum;
                row.POLine = app.list[i].PORel_POLine;
                row.PORelNum = app.list[i].PORel_PORelNum;
                row.LastLine = false
                // row.TranDate = app.searchdata.ArrivedDate;
                row2.PartNum = row.PartNum;
                row2.Company = row.Company;
                row2.LotNum = row.LotNum;
                row2.Received = app.list[i].Received;
                row2.ToWarehouseCode = app.list[i].WarehouseCode;
                row2.ToBinNum = app.list[i].BinNum;
                row2.PartDescription = row.PartDescription;
                row2.TranQty = row.OnhandQty;
                row2.TranDate = app.searchdata.ArrivedDate;
                if(app.list[i].RcvInspectionReq == true){
                    row2.TranType = "PUR-INS"; 
                }else{
                    row2.TranType = "PUR-STK";
                }
                row2.POLine = app.list[i].PORel_POLine + ""; //采购单行
                row2.PackSlip = app.searchdata.PackSlip; //送货单号
                row2.PORelNum = app.list[i].PORelNum +"";//采购下达列
                row2.PONum = app.list[i].PONum; //物料编号
                row2.RMANum = 0;
                row2.ActionNum = 0;
                row2.DMRNum = 0;
                row2.NonConfID = 0;
                row2=post_Tags_obj(row2)
                //row.RowMod = "A"; //固定内容
                tags2.push(row2);
                tags.push(row);
                postlist.push(app.list[i]);

            }
        }
        console.log(JSON.stringify(app.list),3333)
        console.log(JSON.stringify(tags),1111)
        console.log(JSON.stringify(tags2),2222)
       
        // return;
        if (!postlist) {
            api.toast({
                msg: lan['Part_check'],
                location: 'middle'
            });
            return;
        }
        postcount = postlist.length;
        returncount = 0;
        // 遍历postlist数组并执行PoQuantityNum函数
        let promises = postlist.map(item => PoQuantityNum(item));
        // 等待所有异步操作完成后执行提交事件
        Promise.all(promises).then(results => {
        // 判断是否有大于的值
        let hasGreaterThan = results.includes(true);
        let PoQty = localStorage.getItem('PoQty')
        if (hasGreaterThan) {
            if (PoQty == 1) {
                api.confirm({
                    // title: lan['Tips'],
                    msg: lan['PO_Warn'],
                    buttons: [lan['Cancel'], lan['OK']]
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    console.log(index);
                    if (index == 2) {
                        if (ajaxing) { return; } showProgress(lan['Loading']);
                        submitLotNum(postlist);
                    // 点击确认后执行的代码
                    } else if (index == 1) {
                    // 点击取消后执行的代码
                    }
                });
            } else if (PoQty == 2) {
                api.confirm({
                // title: lan['Tips'],
                msg: lan['PO_Stop'],
                buttons: [lan['Cancel'], lan['OK']]
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    console.log(index);
                    if (index == 2) {
                    // 点击确认后执行的代码
                    } else if (index == 1) {
                    // 点击取消后执行的代码
                    }
                });
            }else{
                if (ajaxing) { return; } showProgress(lan['Loading']);
                submitLotNum(postlist);  
            }
        } else {
            if (ajaxing) { return; } showProgress(lan['Loading']);
            submitLotNum(postlist);
            // 没有大于的值，直接执行确认事件
        }
        }).catch(error => {
        // 处理错误
        });

    }


    function submitepicor() {
        //is_header = 0;
        postrows = [];
        postrows = tags
        console.log(JSON.stringify(postlist),8888888)
        returncount++;
        console.log(returncount,77777)
        console.log(postcount,66666)
        submit_porcv();
      
    }
    function submit_porcv() {
        console.log(3333333)
        var postdata1 = [];
        console.log(JSON.stringify(postrows),444444);
        for (var i = 0; i < postrows.length; i++) {
            var row = postrows[i];
            var length = i + 1;
            var LastLine = length === postrows.length;
            var row1 = {
                "CompanyID": userinfo.Company,
                "PlantID": userinfo.Site,
                "UserName": userinfo.Name,
                "Password": userinfo.password,
                "PackSlip": app.searchdata.PackSlip,
                "VendorID": app.searchdata.VendorID,
                "ReceiptDate": app.searchdata.ArrivedDate,
                "PartNum": row.PartNum,
                "Received":row.Received,
                "PartDescription": row.PartDescription,
                "WareHouseCode": row.WarehouseCode,
                "BinNum": row.BinNum,
                "OurQty": row.OurQty,
                "PONum": row.PONum,
                "POLine": row.POLine,
                "PORelNum": row.PORelNum,
                "LotNum": row.LotNum,
                "LastLine": LastLine,
                "ImportNum": app.searchdata.ImportNum
            };

            for (var j = 0; j < postlist.length; j++) {
                var postListItem = postlist[j];
                console.log(JSON.stringify(postListItem),44444)
                if (row.POLine === postListItem.PORel_POLine && row.PORelNum === postListItem.PORel_PORelNum && row.PartNum === postListItem.PODetail_PartNum) {
                    var arr = [];
                    var selectedSerialNumbers = postListItem.SelectedSerialNumbers;
                    if (selectedSerialNumbers && selectedSerialNumbers.length > 0) {
                        for (var k = 0; k < selectedSerialNumbers.length; k++) {
                            var snitem = selectedSerialNumbers[k];
                            delete snitem.xs;
                            delete snitem.tag;
                            delete snitem.type;
                            delete snitem.OnhandQty;
                            arr.push(snitem);
                        }
                        row1.SelectedSerialNumbers = arr;
                    }
                }
            }
            postdata1.push(row1);
        }
        console.log(JSON.stringify(postdata1),1111111)
        //console_debug(postdata1,"");
        // return;
        var data1 = {
            "CompanyID": userinfo.Company,
            "PlantID": userinfo.Site,
            "UserName": userinfo.Name,
            "Password": userinfo.password,
            "Data": JSON.stringify(postdata1)
        }
        console.log(JSON.stringify(data1),1111111)
        // return;
        api.ajax({
            url: wmsserver + 'porcv/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            //dataType: 'text',
            data: {
                body: create_submit_data(data1)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            if (err) {
                hideProgress();
                api.toast({
                    msg: "网络请求出错了",
                    location: 'middle'
                });
                return;
            }
            if (ret && ret.code == 1) {
                console.log(returncount,11111)
                console.log(postcount,222222)
                var param = ret.data.RcvHead[0];
                app.print_btn = false;
                app.receipt_btn = true;
                app.confirm_btn = false;
                app.create_btn = true;
                app.sn_btn = true;
                app.confirm_btn = false;
                api.alert({
                    title: lan['Tips'],
                    msg: lan['Submitted_successfully']
                }, function (ret, err) {
                    is_submit = 1;
                });
                app.Lot_btn = true;
                $('.myselect3').selectpicker('destroy'); // 先销毁
                $('.myselect4').selectpicker('destroy'); // 先销毁
                setTimeout(function(){
                    $('.myselect5').selectpicker('refresh');//在更新
                },200)
                hideProgress();
                // if (returncount == postcount) {
                   

                // }
               
            } else {
                app.receipt_btn = true
                hideProgress();
                errMassage(ret.msg)
            }

        });


    }

  function loadData(scantype) {
        let filter = "?CompID=" + userinfo.Company +"&Site="+userinfo.Site;
        if(app.IncludingClosed == true){
            filter = "?IncludeClosed=true";
        }
      
        if (app.searchdata.PackSlip == "") {
            api.toast({
                msg: lan['DN_No_check'],
                location: 'middle'
            });
            return;
        }

        if (app.searchdata.VendorID) {
            filter += "&VendorID=" + app.searchdata.VendorID;
        }
        if (app.searchdata.PONum) {
            filter += "&PONum=" + app.searchdata.PONum;
        }

        if (app.searchdata.POLine) {
            filter += "&POLine=" + app.searchdata.POLine;
        }

        if (app.searchdata.PORelNum) {
            filter += "&PORelNum=" + app.searchdata.PORelNum;
        }
        if (!app.searchdata.ArrivedDate) {
            api.toast({
                msg: lan['Delivery_Date_check'],
                location: 'middle'
            });
            return;
        }
        console_debug(filter, '');
        userinfo = get_user_info();
        showProgress(lan['Loading']); // 显示加载中提示
        api.ajax({
            url: server + 'BaqSvc/WMS_PORel/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            console.log(JSON.stringify(ret),999999)
            console.log(JSON.stringify(err),888888)
            if (ret && ret.value.length > 0) {
                var newlist = init_list(ret.value);
                console_debug(newlist, err);
                console.log(JSON.stringify(newlist),33333)
                app.list = app.list.concat(newlist);
                console.log(JSON.stringify(app.list),44444)
                app.listids = [];
                for (i in app.list) {
                    app.listids.push(app.list[i].PORel_PONum + '-' + app.list[i].PORel_POLine + '-' + app.list[i].PORel_PORelNum);
                    app.faiIns = localStorage.getItem('faiIns')
                    if(app.faiIns == 1){
                        if(app.list[i].RequiredFAI_c == true){
                            app.list[i].WarehouseCode = "FAIQRY";
                            app.list[i].BinNum = "QI"
                        }
                    }
                    if(app.list[i].Calculated_WarehouseCode){
                      
                        app.getBinNum(i,app.list[i].Calculated_WarehouseCode)
                    }
                }
                setTimeout(function(){
                    hideProgress(); // 隐藏加载中提示
                    $('#exampleModal').modal('hide');
                    app.checkShow = true;
                },500)
              
                const isValueEqual = checkValuesEqual(app.list);
               
                if (scantype == 1) {
                    if(isValueEqual){
                        $("#profile-tab").trigger("click");
                        setTimeout(function () {
                            for (i in app.list) {
                                if (app.list[i].shoucai != 2) {
                                    app.toshou(i, app.list[i]);
                                    setTimeout(function () {
                                        $('.myselect3').selectpicker();
                                        app.getBinNum(i,app.list[i].WarehouseCode)
                                    }, 200);
                                }

                            }
                        }, 500);
                    }else{
                        api.toast({
                            msg:lan['Different_PO'],
                            location: 'middle'
                        })
                        app.list = removeValuesNotEqual(app.list)
                        console.log(JSON.stringify(app.list),33333)
                        setTimeout(function () {
                            for (i in app.list) {
                                if (app.list[i].shoucai != 2) {
                                    app.toshou(i, app.list[i]);
                                    setTimeout(function () {
                                        $('.myselect3').selectpicker();
                                        app.getBinNum(i,app.list[i].WarehouseCode)
                                    }, 200);
                                }

                            }
                        }, 500);
                    }
                   
                }

            } else {
                var PONum = app.searchdata.PONum ? app.searchdata.PONum : '';
                var POLine = app.searchdata.POLine ? app.searchdata.POLine : '';
                var PORelNum = app.searchdata.PORelNum ? app.searchdata.PORelNum : '';
                api.alert({
                    title: lan['Purchase_Order_Load_Error'] + '(' + PONum + ')',
                    msg: lan['POLine'] + ':' + POLine + ', ' + lan['PORelNum'] + ':' + PORelNum,
                }, function (ret, err) {

                });
            }

        });
    }
    
    function removeValuesNotEqual(arr) {
        if (arr.length <= 1) {
            return arr;
        }
        const firstValue = arr[0].PONum;
        for (let i = 1; i < arr.length; i++) {
            if (arr[i].PONum !== firstValue) {
            arr.splice(i, 1);
            i--;
            }
        }
        return arr;
    }

    function checkValuesEqual(arr) {
        if (arr.length <= 1) {
            return true;
        }
        const firstValue = arr[0].PONum;
        for (let i = 1; i < arr.length; i++) {
            if (arr[i].PONum !== firstValue) {
            return false;
            }
        }
        return true;
    }
    function LotAttributeOption(index,item){
        api.ajax({
            url: server + 'BaqSvc/WMS_LotAttributeOption/?CompID=' + userinfo.Company + '&PartNum=' + item.PODetail_PartNum + '',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            if (ret && ret.value.length>0) {
                console.log(JSON.stringify(ret.value[0]), 666666)
                var keys = Object.keys(ret.value[0]);
                var allN = keys.filter(function(key) {
                    return key !== "Part_Company" && key !== "RowIdent";
                    }).every(function(key) {
                    return ret.value[0][key] === "N";
                });
                console.log(allN,777777)
                if (allN) {
                   app.$set(app.$data.list[index],'BatchProperties',true)
                } else {
                    app.$set(app.$data.list[index],'BatchProperties',false)
                }

            } 

        });
    }
    function init_list(data) {
        var ret = [];
        for (i in data) {
            if (app.searchdata.VendorID) {
                if (data[i].Vendor_VendorID != app.searchdata.VendorID) {
                    continue;
                }
            }
            data[i].shoucai = 1;
            data[i].InputOurQty = '';
            data[i].oneQty = '';
            data[i].tailQty = '';
            data[i].totalQty = '';
            data[i].LotNum = ''; //批号
            data[i].is_Lot = -1; //批号判断 -1 未查询  1 需创建 2 不需创建
            data[i].is_SerialNum = -1; //序列号判断 -1 未查询  1 需创建 2 不需创建
            if (data[i].Part_TrackLots) {
                data[i].is_Lot = 1
                //that.GenerateNewLotNum(i, shoucai);
            } else {
                data[i].is_Lot = 2
            }
            if (data[i].Part_TrackSerialNum) {
                data[i].is_SerialNum = 1; 
            } else {
                data[i].is_SerialNum = 2; 
            }
            data[i].BatchProperties = data[i].Part_TrackLots//批次属性是否需要
            data[i].RequiredFAI_c =data[i].PODetail_RequiredFAI_c
            data[i].WarehouseCode = data[i].Calculated_WarehouseCode
            data[i].BinNum = data[i].Calculated_BinNum
            data[i].WareHouseCodeList = app.WareHouseCodeList
            data[i].binNumList = app.binNumList
            data[i].SNFormat =data[i].Part_SNFormat
            data[i].SNBaseDataType =data[i].Part_SNBaseDataType
            data[i].MaskType =data[i].SerialMask_MaskType
            data[i].SNPrefix =data[i].Part_SNPrefix
            data[i].AllowDecimals =data[i].UOM_AllowDecimals
            data[i].NumOfDec =data[i].UOM_NumOfDec
            data[i].RcvInspectionReq =data[i].PODetail_RcvInspectionReq
            data[i].print = false;
            data[i].tags = [];
            data[i].tags2 = [];
            data[i].SelectedSerialNumbers = [];
            data[i].RevisionNum = data[i].PODetail_RevisionNum
            data[i].BatchCheck =null;//批次属性按钮监听
            data[i].createCheck = false;//生成序号按钮监听
            data[i].snsCheck = false;
            data[i].Received = false
            data[i].entryCheck = false;//登记序号按钮监听
            data[i].attribute_btn = false;
            ret.push(data[i]);
           
        }
        console_debug(ret, 'init_list');
        return ret;
    }


</script>

</html>